﻿using Com.Ctrip.Framework.Apollo;
using Com.Ctrip.Framework.Apollo.Enums;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace Helpers
{
    public static class ApolloHelper
    {
        /// <summary>
        /// apollo配置,需要配置节apollo
        /// </summary>
        public static IHostBuilder AddApolloz(this IHostBuilder hostBuilder)
        {
            hostBuilder.ConfigureAppConfiguration((context, builder) =>
            {
                var config = builder.Build().GetSection("apollo");
                var apolloOptions = config.Get<ApolloOptions>();
                Console.WriteLine($"apollo配置--{JsonConvert.SerializeObject(apolloOptions, new JsonSerializerSettings() { Formatting = Formatting.Indented })}");
                builder.AddApollo(config);
            });
            return hostBuilder;
        }
    }
}
